import React, { Component } from 'react'
import { connect } from 'react-redux'
import { createIncrement, createDecrement } from '../../redux/actions/count'

class Count extends Component {
  add = () => {
    this.props.increment(1)
  }

  sub = () => {
    this.props.decrement(1)
  }

  render() {
    return (
      <div>
        <p>我是Count组件</p>
        <p>Person组件总人数为: { this.props.personList?.length }</p>
        <h3>总和为: { this.props.count }</h3>
        <button onClick={this.add}>加1</button>
        <button onClick={this.sub}>减1</button>
      </div>
    )
  }
}

export default connect(
  state => ({count: state.count, personList: state.personList}),
  {
    increment: createIncrement,
    decrement: createDecrement
  }
)(Count)
